package org.rcgwt.client.ui.validator.impl;

import org.rcgwt.client.ui.validator.ICharacterSets;
import org.rcgwt.client.ui.validator.IClientValidatorContext;
import org.rcgwt.client.ui.validator.IFilter;
import org.rcgwt.client.ui.validator.ISingleton;
import org.rcgwt.client.ui.validator.IValidatorElement;

/**
 * Filter which filters scientific numbers (like digits, dot, power exponent,
 * plus, minus)
 * 
 * @author Elian ORIOU
 * 
 */

public class ScientificFilter implements IFilter, ISingleton {

	private static final ScientificFilter INSTANCE = new ScientificFilter();

	private static final String MY_PATTERN = ICharacterSets.NUM_SET;

	protected ScientificFilter() {

	}

	@Override
	public boolean filter(IClientValidatorContext context, char c) {
		if (MY_PATTERN.indexOf(c) != -1 || c == '.' || c == 'E' || c == 'e'
				|| c == '+' || c == '-') {
			return true;
		}
		return false;
	}

	public static IValidatorElement getInstance() {
		return INSTANCE;
	}

}
